package com.leoman.plz_p.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.leoman.plz_p.R;
import com.leoman.plz_p.module.bean.VideoListBean;
import com.leoman.plz_p.weidget.RoundedTransformationBuilder;

import butterknife.Bind;
import cn.com.corelib.utils.DisplayUtil;
import cn.com.corelib.utils.adapter.BaseAdapterHelper;
import cn.com.corelib.utils.adapter.normal.QuickAdapter;

/**
 * Created by guoh on 2018/7/9.
 */
public class VideoListAdapter extends QuickAdapter<VideoListBean> {
    @Bind(R.id.iv_image)
    ImageView ivImage;
    @Bind(R.id.iv_play)
    ImageView ivPlay;
    @Bind(R.id.tv_text)
    TextView tvText;
    @Bind(R.id.tv_theory)
    TextView tvTheory;
    @Bind(R.id.tv_test)
    TextView tvTest;

    public VideoListAdapter(Context context) {
        super(context, R.layout.item_video_list);
    }

    @Override
    protected void convert(BaseAdapterHelper helper, VideoListBean item, int position) {
        if (!TextUtils.isEmpty(item.getImage())) {
            Glide.with(context).load(item.getImage()).centerCrop().transform(new CenterCrop(context), new RoundedTransformationBuilder()
                    .cornerRadius(DisplayUtil.dip2px(context, 5)).build(context)).into((ImageView) helper.getView(R.id.iv_image));
        }
        helper.setText(R.id.tv_text,item.getName());
        helper.setTag(R.id.iv_play,position)
                .setOnClickListener(R.id.iv_play, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (ls!=null){
                            ls.onVideoClickListener(Integer.parseInt(v.getTag().toString()));
                        }
                    }
                });
    }


    public void setOnItemClickListener(onItemClickListener ls) {
        this.ls = ls;
    }

    private onItemClickListener ls;

    public interface onItemClickListener{
        void onVideoClickListener(int position);
    }
}
